//
//  CZQMainTabBarController.m
//  LoveBeer
//
//  Created by 崔正强 on 17/4/26.
//  Copyright © 2017年 崔正强. All rights reserved.
//

#import "CZQMainTabBarController.h"
#import "CZQNavigationController.h"
#import "HMAlphaAnimator.h"
#import "CZQMainTabBar.h"
#import "LoveBeer.pch"

@interface CZQMainTabBarController ()

@property (strong, nonatomic) HMAlphaAnimator *animator;

@end

@implementation CZQMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTabBars];
    
    [self setupModalPresentation];
    
    //自定义tabBar
    CZQMainTabBar *czqTabBar = [[CZQMainTabBar alloc] init];
    
    [self setValue:czqTabBar forKey:@"tabBar"];
    
    //设置字体渲染颜色
    self.tabBar.tintColor = appColor;
}

- (void)setupTabBars {
    
    [self addNavControllerWithViewController:@"CZQHomeViewController" title:@"首页" imgName:@"v2_home"];
    
    [self addNavControllerWithViewController:@"CZQSupermarketViewController" title:@"闪购超市" imgName:@"v2_order"];
    
    [self addNavControllerWithViewController:@"CZQShoppingCarViewController" title:@"购物车" imgName:@"shopCart"];
    
    [self addNavControllerWithViewController:@"CZQMineViewController" title:@"我的" imgName:@"v2_my"];
    
}


- (void)addNavControllerWithViewController:(NSString *)clsName title:(NSString *)title imgName:(NSString *)imgName{
    
    Class cls = NSClassFromString(clsName);
    UIViewController *controller = [cls new];
    CZQNavigationController *navController = [[CZQNavigationController alloc] initWithRootViewController:controller];
    //字体颜色
    self.tabBar.tintColor = [UIColor colorWithRed:254/255.0 green:213/255.0 blue:48/255.0 alpha:1.0];
    navController.tabBarItem.title = title;
    
    [navController.tabBarItem setImage:[UIImage imageNamed:imgName]];
    
    [navController.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_r",imgName]]];
    
    [self addChildViewController:navController];
}

#pragma - 设置动画效果 -
- (void)setupModalPresentation {
    
    //1.设置modal展示样式
    self.modalPresentationStyle = UIModalPresentationCustom;
    
    self.animator = [HMAlphaAnimator new];
    
    //2.设置转场代理 -> 自定义转场动画
    self.transitioningDelegate = self.animator;
    
}


@end
